import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
  UseGuards,
  ValidationPipe,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { AccessService } from './access.service';
import { CreateAccessDto } from './dto/create-access.dto';
import { UpdateAccessDto } from './dto/update-access.dto';

@Controller('access')
export class AccessController {
  constructor(private readonly accessService: AccessService) {}

  @Post('/add')
  @UseGuards(AuthGuard('jwt')) //jwt策略，身份鉴权
  create(@Body(new ValidationPipe()) createAccessDto: CreateAccessDto) {
    return this.accessService.create(createAccessDto);
  }

  @Get('/list')
  @UseGuards(AuthGuard('jwt')) //jwt策略，身份鉴权
  findAll(@Query('parentId') parentId: string) {
    return this.accessService.findAll(parentId);
  }

  @Get(':id')
  @UseGuards(AuthGuard('jwt')) //jwt策略，身份鉴权
  findOne(@Param('id') id: string) {
    return this.accessService.findOne(+id);
  }

  @Patch(':id')
  @UseGuards(AuthGuard('jwt')) //jwt策略，身份鉴权
  update(@Param('id') id: string, @Body() updateAccessDto: UpdateAccessDto) {
    return this.accessService.update(id, updateAccessDto);
  }

  @Delete(':id')
  @UseGuards(AuthGuard('jwt')) //jwt策略，身份鉴权
  remove(@Param('id') id: string) {
    return this.accessService.remove(id);
  }
}
